package com.example.time_planner.activities;

import java.util.List;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.widget.AbsListView;

import com.example.time_planner.R;
import com.example.time_planner.dataBase.TaskHelper;
import com.example.time_planner.tasks_view.DynamicListView;
import com.example.time_planner.tasks_view.StableArrayAdapter;

public class TaskList extends Activity {
	private static int taskID = -1;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_list_view);

		TaskHelper dataBase = new TaskHelper(TaskList.this);
		List<String> mList = dataBase.getNames();

		StableArrayAdapter adapter = new StableArrayAdapter(this,
				R.layout.text_view, mList, this);
		DynamicListView listView = (DynamicListView) findViewById(R.id.listview);

		listView.setList(mList);
		listView.setAdapter(adapter);
		listView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
	}

	/**
	 * 
	 * @return the last taskID that was clicked (only once, after that - return null)
	 */
	public Integer getTaskID() {
		int result = taskID;
		taskID = -1;
		if(result == -1)
		{
			return null;
		}
		return result;
	}
	public void showTaskActivity(Integer id) {
		taskID = id;
		Intent activity = new Intent(TaskList.this, CreateTaskActivity.class);
		startActivity(activity);
	}
}
